package util;

import java.util.HashMap;
import java.util.Map;

public class TranslationTable {
	private final Map CODONS_MAP = new HashMap();

	private Map AMINO_ACIDS_MAP = new HashMap();

	public TranslationTable() {
		fillTheMap();
		fillAaMap();
	}

	public String translate(String key) {
		String toReturn = (String) CODONS_MAP.get(key);

		if (toReturn == null) {
			throw new IllegalArgumentException(
					"Unrecognized String to be translated..." + key);
		} else {
			return toReturn;
		}
	}

	public String translateAa(String key) {
		String toReturn = (String) AMINO_ACIDS_MAP.get(key);

		if (toReturn == null) {
			throw new IllegalArgumentException(
					"Unrecognized String to be translated..." + key);
		} else {
			return toReturn;
		}
	}

	private void fillAaMap() {
		AMINO_ACIDS_MAP.put("A", "A"); // Alanine
		AMINO_ACIDS_MAP.put("C", "G"); // Cysteine
		AMINO_ACIDS_MAP.put("D", "G"); // Aspartic
		AMINO_ACIDS_MAP.put("E", "G"); // Glutamic
		AMINO_ACIDS_MAP.put("F", "A"); // Phenylalanine
		AMINO_ACIDS_MAP.put("G", "G"); // Glycine
		AMINO_ACIDS_MAP.put("H", "G"); // Histidine
		AMINO_ACIDS_MAP.put("I", "A"); // Isoleucine
		AMINO_ACIDS_MAP.put("K", "G"); // Lysine
		AMINO_ACIDS_MAP.put("L", "A"); // Leucine
		AMINO_ACIDS_MAP.put("M", "A"); // Methionine
		AMINO_ACIDS_MAP.put("N", "G"); // Aspargine
		AMINO_ACIDS_MAP.put("P", "A"); // Proline
		AMINO_ACIDS_MAP.put("Q", "G"); // Glutamine
		AMINO_ACIDS_MAP.put("R", "G"); // Argenine
		AMINO_ACIDS_MAP.put("T", "A"); // Threonine
		AMINO_ACIDS_MAP.put("V", "A"); // Valine
		AMINO_ACIDS_MAP.put("W", "G"); // Thriptopane
		AMINO_ACIDS_MAP.put("Y", "G"); // Thyrosine
		AMINO_ACIDS_MAP.put("S", "A"); // Serine ???
	}

	private void fillTheMap() {
		// [A] Alanine Ala A GCA,GCC,GCG,GCU
		CODONS_MAP.put("GCA", "A");
		CODONS_MAP.put("GCC", "A");
		CODONS_MAP.put("GCG", "A");
		CODONS_MAP.put("GCT", "A");

		// [G] Cysteine Cys C UGC,UGU
		CODONS_MAP.put("TGC", "G");
		CODONS_MAP.put("TGT", "G");

		// [G] Aspartic Acid Asp D GAC,GAU
		CODONS_MAP.put("GAC", "G");
		CODONS_MAP.put("GAT", "G");

		// [G] Glutamic Acid Glu E GAA,GAG
		CODONS_MAP.put("GAA", "G");
		CODONS_MAP.put("GAG", "G");

		// [A] Phenylalanine Phe F UUC,UUU
		CODONS_MAP.put("TTC", "A");
		CODONS_MAP.put("TTT", "A");

		// [G] Glycine Gly G GGA,GGC,GGG,GGU
		CODONS_MAP.put("GGA", "G");
		CODONS_MAP.put("GGC", "G");
		CODONS_MAP.put("GGG", "G");
		CODONS_MAP.put("GGT", "G");

		// [G] Histidine His H CAC,CAU
		CODONS_MAP.put("CAC", "G");
		CODONS_MAP.put("CAT", "G");

		// [A] Isoleucine Ile I AUA,AUC,AUU
		CODONS_MAP.put("ATA", "A");
		CODONS_MAP.put("ATC", "A");
		CODONS_MAP.put("ATT", "A");

		// [G] Lysine Lys K AAA,AAG
		CODONS_MAP.put("AAA", "G");
		CODONS_MAP.put("AAG", "G");

		// [A] Leucine Leu L UUA,UUG,CUA,CUC,CUG,CUU
		CODONS_MAP.put("TTA", "A");
		CODONS_MAP.put("TTG", "A");
		CODONS_MAP.put("CTA", "A");
		CODONS_MAP.put("CTC", "A");
		CODONS_MAP.put("CTG", "A");
		CODONS_MAP.put("CTT", "A");

		// [A] Methionine Met M AUG
		CODONS_MAP.put("ATG", "A");

		// [G] Asparagine Asn N AAC,AAU
		CODONS_MAP.put("AAC", "G");
		CODONS_MAP.put("AAT", "G");

		// [A] Proline Pro P CCA,CCC,CCG,CCU
		CODONS_MAP.put("CCA", "A");
		CODONS_MAP.put("CCC", "A");
		CODONS_MAP.put("CCG", "A");
		CODONS_MAP.put("CCT", "A");

		// [G] Glutamine Gln Q CAA,CAG
		CODONS_MAP.put("CAA", "G");
		CODONS_MAP.put("CAG", "G");

		// [G] Arginine Arg R AGA,AGG,CGA,CGC,CGG,CGU
		CODONS_MAP.put("CGA", "G");
		CODONS_MAP.put("CGC", "G");
		CODONS_MAP.put("CGG", "G");
		CODONS_MAP.put("CGT", "G");
		CODONS_MAP.put("AGA", "G");
		CODONS_MAP.put("AGG", "G");

		// [A] Serine Ser S UCA,UCC,UCG,UCU,AGC,AGU
		CODONS_MAP.put("TCA", "A");
		CODONS_MAP.put("TCC", "A");
		CODONS_MAP.put("TCG", "A");
		CODONS_MAP.put("TCT", "A");

		// [G] Serine Ser S UCA,UCC,UCG,UCU,AGC,AGU
		CODONS_MAP.put("AGC", "G");
		CODONS_MAP.put("AGT", "G");

		// [A] Threonine Thr T ACA,ACC,ACG,ACU
		CODONS_MAP.put("ACA", "A");
		CODONS_MAP.put("ACC", "A");
		CODONS_MAP.put("ACG", "A");
		CODONS_MAP.put("ACT", "A");

		// [A] Valine Val V GUA,GUC,GUG,GUU
		CODONS_MAP.put("GTA", "A");
		CODONS_MAP.put("GTC", "A");
		CODONS_MAP.put("GTG", "A");
		CODONS_MAP.put("GTT", "A");

		// [G] Tryptophan Trp W UGG
		CODONS_MAP.put("TGG", "G");

		// [G] Tyrosine Tyr Y UAC,UAU
		CODONS_MAP.put("TAC", "G");
		CODONS_MAP.put("TAT", "G");

		// Stop Codons . UAA,UAG,UGA
		CODONS_MAP.put("TAA", "G");
		CODONS_MAP.put("TAG", "G");
		CODONS_MAP.put("TGA", "G");

		// Single nucleotides codes
		CODONS_MAP.put("A", "G");
		CODONS_MAP.put("G", "G");
		CODONS_MAP.put("T", "A");
		CODONS_MAP.put("C", "A");
	}
}
